package com.ruoyi.web.controller.api;


import com.ruoyi.common.constant.CacheConstants;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.dto.GetPairsListDto;
import com.ruoyi.trade.service.ITPairsService;
import com.ruoyi.vo.GetPairsListVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Set;

@RequestMapping("api/pairs")
@Api(value = "交易对接口", tags = {"交易对接口"})
@RestController
public class ApiPairsController extends BaseController {

    @Autowired
    private ITPairsService tPairsService;

    @Autowired
    private RedisCache redisCache;

    @ApiOperation(value = "获取交易对信息")
    @PostMapping(value = "/getPairsList")
    public @ResponseBody
    R<List<GetPairsListVo>> getPairsList(@RequestBody GetPairsListDto getPairsListDto) {
        String type = getPairsListDto.getType();
        if(StringUtils.isEmpty(type)){
            throw new ServiceException("请传入交易对类型");
        }
        List<GetPairsListVo> pairsListVo =  tPairsService.getPairsList(type);
        return R.ok(pairsListVo);
    }


    @ApiOperation(value = "获取交易对信息")
    @PostMapping(value = "/test")
    public @ResponseBody
    R<Object> test() {
        String redisKey = "kline:CONTRACT:1m:BTC/USDT";
        Set<String> set = redisCache.zsetRangByScore(redisKey, 1726887891886L, 1727060691886L);
        return R.ok(set);
    }


}
